clear;
D = dlmread('Toy1.txt');
C = D(:,4);
S = [D(:, 1:3) ones(size(D,1),1)];
a = onlineperceptron(10, 4, polykernel(3));
for i=1:size(S,1)
a.train(S(i,:), C(i));
end
res = 0;
for i=1:size(S,1)
res = res + a.predict(S(i,:)) - C(i);
end
res
b = onlineperceptron(10, 4, polykernel(3));
for i=1:size(S,1)
b.train(S(i,:), C(i));
end
res = 0;
for i=1:size(S,1)
res = res + b.predict(S(i,:)) - C(i);
end
res

[X,Y,Z] = meshgrid(0:.1:1, 0:.1:1, 0:.1:1);                                
TS=[reshape(X,numel(X),1) reshape(Y,numel(Y),1) reshape(Z,numel(Z),1) ones(numel(X),1)];
TC = b.predict(TS);
hold on;
c0ind = find(TC > 0);
c1ind = find(TC < 0);
plot3(TS(c0ind,1),TS(c0ind,2), TS(c0ind,3), 'r.', TS(c1ind,1),TS(c1ind,2), TS(c1ind,3), 'g.');
c0ind = find(C > 0);
c1ind = find(C < 0);
plot3(S(c0ind,1),S(c0ind,2), S(c0ind,3), 'ro', S(c1ind,1),S(c1ind,2), S(c1ind,3), 'go');

hold off;